///*This source code copyrighted by DroidSerif-Regular Foo' Productions (2004-2013)
//and may not be redistributed without written permission.*/
//
////The headers
//#include "SDL.h"
//#include "SDL_image.h"
//#include "SDL_ttf.h"
//#include <string>
//
////Screen attributes
//const int SCREEN_WIDTH = 640;
//const int SCREEN_HEIGHT = 480;
//const int SCREEN_BPP = 32;
//
////The surfaces
//SDL_Surface *background = NULL;
//SDL_Surface *message = NULL;
//SDL_Surface *screen = NULL;
//
////The event structure
//SDL_Event event;
//
////The font
//TTF_Font *font = NULL;
//
////The color of the font
//SDL_Color textColor = { 0xFF, 0xFF, 0xFF };
//
////The key press interpreter
//class StringInput
//{
//    private:
//    //The storage string
//    std::string str;
//
//    //The text surface
//    SDL_Surface *text;
//
//    public:
//    //Initializes variables
//    StringInput();
//
//    //Does clean up
//    ~StringInput();
//
//    //Handles input
//    void handle_input();
//
//    //Shows the message on screen
//    void show_centered();
//};
//
//SDL_Surface *load_image( std::string filename )
//{
//    //The image that's loaded
//    SDL_Surface* loadedImage = NULL;
//
//    //The optimized surface that will be used
//    SDL_Surface* optimizedImage = NULL;
//
//    //Load the image
//    loadedImage = IMG_Load( filename.c_str() );
//
//    //If the image loaded
//    if( loadedImage != NULL )
//    {
//        //Create an optimized surface
//        optimizedImage = SDL_DisplayFormat( loadedImage );
//
//        //Free the old surface
//        SDL_FreeSurface( loadedImage );
//
//        //If the surface was optimized
//        if( optimizedImage != NULL )
//        {
//            //Color key surface
//            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
//        }
//    }
//
//    //Return the optimized surface
//    return optimizedImage;
//}
//
//void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
//{
//    //Holds offsets
//    SDL_Rect offset;
//
//    //Get offsets
//    offset.x = x;
//    offset.y = y;
//
//    //Blit
//    SDL_BlitSurface( source, clip, destination, &offset );
//}
//
//bool init()
//{
//    //Initialize all SDL subsystems
//    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
//    {
//        return false;
//    }
//
//    //Set up the screen
//    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//
//    //If there was an error in setting up the screen
//    if( screen == NULL )
//    {
//        return false;
//    }
//
//    //Initialize SDL_ttf
//    if( TTF_Init() == -1 )
//    {
//        return false;
//    }
//
//    //Set the window caption
//    SDL_WM_SetCaption( "High Score", NULL );
//
//    //If everything initialized fine
//    return true;
//}
//
//bool load_files()
//{
//    //Load the background image
//    background = load_image( "background.png" );
//
//    //Open the font
//    font = TTF_OpenFont( "DroidSerif-Regular.ttf", 42 );
//
//    //If there was a problem in loading the background
//    if( background == NULL )
//    {
//        return false;
//    }
//
//    //If there was an error in loading the font
//    if( font == NULL )
//    {
//        return false;
//    }
//
//    //If everything loaded fine
//    return true;
//}
//
//void clean_up()
//{
//    //Free the surfaces
//    SDL_FreeSurface( background );
//    SDL_FreeSurface( message );
//
//    //Close the font that was used
//    TTF_CloseFont( font );
//
//    //Quit SDL_ttf
//    TTF_Quit();
//
//    //Quit SDL
//    SDL_Quit();
//}
//
//StringInput::StringInput()
//{
//    //Initialize the string
//    str = "";
//
//    //Initialize the surface
//    text = NULL;
//
//    //Enable Unicode
//    SDL_EnableUNICODE( SDL_ENABLE );
//}
//
//StringInput::~StringInput()
//{
//    //Free text surface
//    SDL_FreeSurface( text );
//
//    //Disable Unicode
//    SDL_EnableUNICODE( SDL_DISABLE );
//}
//
//void StringInput::handle_input()
//{
//    //If a key was pressed
//    if( event.type == SDL_KEYDOWN )
//    {
//        //Keep a copy of the current version of the string
//        std::string temp = str;
//
//        //If the string less than maximum size
//        if( str.length() <= 16 )
//        {
//            //If the key is a space
//            if( event.key.keysym.unicode == (Uint16)' ' )
//            {
//                //Append the character
//                str += (char)event.key.keysym.unicode;
//            }
//            //If the key is a number
//            else if( ( event.key.keysym.unicode >= (Uint16)'0' ) && ( event.key.keysym.unicode <= (Uint16)'9' ) )
//            {
//                //Append the character
//                str += (char)event.key.keysym.unicode;
//            }
//            //If the key is a uppercase letter
//            else if( ( event.key.keysym.unicode >= (Uint16)'A' ) && ( event.key.keysym.unicode <= (Uint16)'Z' ) )
//            {
//                //Append the character
//                str += (char)event.key.keysym.unicode;
//            }
//            //If the key is a lowercase letter
//            else if( ( event.key.keysym.unicode >= (Uint16)'a' ) && ( event.key.keysym.unicode <= (Uint16)'z' ) )
//            {
//                //Append the character
//                str += (char)event.key.keysym.unicode;
//            }
//        }
//
//        //If backspace was pressed and the string isn't blank
//        if( ( event.key.keysym.sym == SDLK_BACKSPACE ) && ( str.length() != 0 ) )
//        {
//            //Remove a character from the end
//            str.erase( str.length() - 1 );
//        }
//
//        //If the string was changed
//        if( str != temp )
//        {
//            //Free the old surface
//            SDL_FreeSurface( text );
//
//            //Render a new text surface
//            text = TTF_RenderText_Solid( font, str.c_str(), textColor );
//        }
//    }
//}
//
//void StringInput::show_centered()
//{
//    //If the surface isn't blank
//    if( text != NULL )
//    {
//        //Show the name
//        apply_surface( ( SCREEN_WIDTH - text->w ) / 2, ( SCREEN_HEIGHT - text->h ) / 2, text, screen );
//    }
//}
//
//int main( int argc, char* args[] )
//{
//    //Quit flag
//    bool quit = false;
//
//    //Keep track if whether or not the user has entered their name
//    bool nameEntered = false;
//
//    //Initialize
//    if( init() == false )
//    {
//        return 1;
//    }
//
//    //The gets the user's name
//    StringInput name;
//
//    //Load the files
//    if( load_files() == false )
//    {
//        return 1;
//    }
//
//    //Set the message
//    message = TTF_RenderText_Solid( font, "New High Score! Enter Name:", textColor );
//
//    //While the user hasn't quit
//    while( quit == false )
//    {
//        //While there's events to handle
//        while( SDL_PollEvent( &event ) )
//        {
//            //If the user hasn't entered their name yet
//            if( nameEntered == false )
//            {
//                //Get user input
//                name.handle_input();
//
//                //If the enter key was pressed
//                if( ( event.type == SDL_KEYDOWN ) && ( event.key.keysym.sym == SDLK_RETURN ) )
//                {
//                    //Change the flag
//                    nameEntered = true;
//
//                    //Free the old message surface
//                    SDL_FreeSurface( message );
//
//                    //Change the message
//                    message = TTF_RenderText_Solid( font, "Rank: 1st", textColor );
//                }
//            }
//
//            //If the user has Xed out the window
//            if( event.type == SDL_QUIT )
//            {
//                //Quit the program
//                quit = true;
//            }
//        }
//
//        //Apply the background
//        apply_surface( 0, 0, background, screen );
//
//        //Show the message
//        apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( ( SCREEN_HEIGHT / 2 ) - message->h ) / 2, message, screen );
//
//        //Show the name on the screen
//        name.show_centered();
//
//        //Update the screen
//        if( SDL_Flip( screen ) == -1 )
//        {
//            return 1;
//        }
//    }
//
//    //Clean up
//    clean_up();
//
//    return 0;
//}
